<template>
	<view class="container">
		<view class="header">
			<text class="logo">logo</text>
			<text class="welcome">欢迎回来</text>
		</view>
		


		<view class="form-container">
			<view class="input-group">
				<uni-icons type="phone" size="20" color="#9CA3AF" class="input-icon"></uni-icons>
				<input type="tel" placeholder="请输入手机号" @input="getnumber" class="input-field" placeholder-class="placeholder" />
			</view>

			<view class="input-group">
				<uni-icons type="locked" size="20" color="#9CA3AF" class="input-icon"></uni-icons>
				<input type="password" placeholder="请输入密码" class="input-field" @input="getpassw" placeholder-class="placeholder" />
			</view>

			<view class="forgot-password">
				<text @click="navigateToForgotPassword">忘记密码？</text>
			</view>

			<button class="login-btn" @click="handleLogin">登录</button>

			<view class="divider">

			</view>


			<view class="agreement">
				<checkbox-group @change="toggleAgreement" >
					<label>
						<checkbox :checked="agreed"  color="#4A90E2" style="transform:scale(0.8)" />
						<text class="agreement-text">
							我已阅读并同意
							<text class="link" @click="navigateToUserAgreement">《用户协议》</text>
							和
							<text class="link" @click="navigateToUserAgreement">《隐私政策》</text>
						</text>
					</label>
				</checkbox-group>
			</view>


		</view>
	</view>
</template>

<script>
	import {
		curl
	} from 'common/api.js';
	export default {
		data() {
			return {
				username: '',
				password: '',
				agreed:false

			}
		},

		onLoad() {},
		onShow() {},
		methods: {
			navigateToUserAgreement(){
				uni.navigateTo({
					url:"/pages/login/agreement"
				})
			},
			 toggleAgreement  (e){
			  console.log(e.detail.value)
			  var arr=e.detail.value;
			  this.agreed=arr.length>0?1:0
			},
			handleLogin() {
				var username = this.username;
				var password = this.password;
				var agreed = this.agreed;

				if (!username || !password) {
					uni.showToast({
						title: '请输入手机号和密码',
						icon: 'none'
					});
					return;
				}
				if (!agreed) {
					uni.showToast({
						title: '请先同意用户协议和隐私政策',
						icon: 'none'
					});
					return;
				}


				console.log(username);
				curl('user/login', {
					account: username,
					password: password
				}).then((res) => {
					console.log(res);

					uni.showToast({
						title: res.msg,
						icon: 'none'
					})

					if (res.code == 1) {
						uni.setStorageSync('token', res.data.userinfo.token);
						uni.setStorageSync('user', res.data.userinfo);
						uni.switchTab({
							url: '/pages/index/index'
						})
					}

				});


			},
			getnumber(ret) {
				console.log(ret);
				this.username = ret.detail.value;
			},
			getpassw(ret) {
				console.log(ret);
				this.password = ret.detail.value;
			},


		}
	}
</script>

<style>
	page {
		height: 100%;
	}

	.container {
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		background-color: #ffffff;
		padding: 0 32rpx;
		box-sizing: border-box;
	}

	.header {
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-top: 128rpx;
		padding-bottom: 64rpx;
	}

	.logo {
		font-family: 'Pacifico', cursive;
		font-size: 48rpx;
		color: #4A90E2;
		margin-bottom: 24rpx;
	}

	.welcome {
		font-size: 28rpx;
		color: #6B7280;
	}

	.form-container {
		width: 100%;
		display: flex;
		flex-direction: column;
	}

	.input-group {
		width: 100%;
		height: 96rpx;
		position: relative;
		margin-bottom: 32rpx;
	}

	.input-icon {
		position: absolute;
		left: 24rpx;
		top: 50%;
		transform: translateY(-50%);
		z-index: 1;
	}

	.eye-icon {
		position: absolute;
		right: 24rpx;
		top: 50%;
		transform: translateY(-50%);
		z-index: 1;
	}

	.input-field {
		width: 100%;
		height: 100%;
		padding-left: 80rpx;
		padding-right: 80rpx;
		border: 1px solid #E5E7EB;
		border-radius: 8rpx;
		font-size: 28rpx;
		color: #111827;
		box-sizing: border-box;
	}

	.placeholder {
		color: #9CA3AF;
	}

	.forgot-password {
		width: 100%;
		display: flex;
		justify-content: flex-end;
		margin-bottom: 48rpx;
	}

	.forgot-password text {
		font-size: 24rpx;
		color: #6B7280;
	}

	.login-btn {
		width: 100%;
		height: 96rpx;
		background-color: #4A90E2;
		color: #ffffff;
		font-size: 32rpx;
		border-radius: 8rpx;
		margin: 0;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.divider {
		width: 100%;
		display: flex;
		align-items: center;
		margin: 64rpx 0;
	}

	.divider-line {
		flex: 1;
		height: 1px;
		background-color: #E5E7EB;
	}

	.divider-text {
		padding: 0 24rpx;
		font-size: 24rpx;
		color: #6B7280;
	}

	.social-login {
		width: 100%;
		display: flex;
		justify-content: center;
		gap: 48rpx;
		margin-bottom: 64rpx;
	}

	.social-btn {
		width: 80rpx;
		height: 80rpx;
		border: 1px solid #E5E7EB;
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 0;
		margin: 0;
		background-color: transparent;
	}

	.agreement {
		width: 100%;
		margin-bottom: 64rpx;
	}

	.agreement-text {
		font-size: 24rpx;
		color: #6B7280;
	}

	.link {
		color: #4A90E2;
	}

	.register {
		width: 100%;
		display: flex;
		justify-content: center;
		gap: 16rpx;
	}

	.register-text {
		font-size: 24rpx;
		color: #6B7280;
	}

	.register-link {
		font-size: 24rpx;
		color: #4A90E2;
	}
</style>